package com.blensmile.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.blensmile.R;
import com.blensmile.activity.MediaPlayerItemTestActivity;
import com.blensmile.entities.MediaTestBean;
import com.blensmile.view.PlayVoiceCircleView;
import com.blensmile.view.PlayVoiceView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Blensmile on 2016/12/29.
 */
public class MediaTestAdapter extends RecyclerView.Adapter<MediaTestAdapter.MediaTestHolder>{

    private ArrayList<MediaTestBean> mList;
    private Context context;

    public MediaTestAdapter(Context context,List<MediaTestBean> mDataset) {
        this.mList = (ArrayList)mDataset;
        this.context = context;
    }

    @Override
    public MediaTestHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_media_test,parent,false);
        return new MediaTestHolder(view);
    }

    @Override
    public void onBindViewHolder(MediaTestHolder holder, final int position) {
        final MediaTestBean bean = mList.get(position);
        if (bean != null) {
            holder.pvPlayer.setSoundUrl(bean.getUrl());
//            holder.pvPlayer.setTime(bean.getTime());
            holder.imgAvatar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, MediaPlayerItemTestActivity.class);
                    intent.putExtra("url",bean.getUrl());
                    intent.putParcelableArrayListExtra("data",mList);
                    context.startActivity(intent);
                }
            });
            holder.tvName.getBackground().setColorFilter(0xff00ffff, PorterDuff.Mode.SRC_IN);
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class MediaTestHolder extends RecyclerView.ViewHolder{
        private PlayVoiceCircleView pvPlayer;
        private TextView tvName;
        private ImageView imgAvatar;

        public MediaTestHolder(View itemView) {
            super(itemView);
            imgAvatar = (ImageView)itemView.findViewById(R.id.img_avatar);
            tvName = (TextView)itemView.findViewById(R.id.tv_name);
            pvPlayer = (PlayVoiceCircleView) itemView.findViewById(R.id.pv_player);
        }
    }
}